// Copyright (c) Omar AL Zabir. All rights reserved.
// For continued development and updates, visit http://msmvps.com/omar

using System;
using System.ComponentModel;
using System.ComponentModel.Design;
using System.Collections;
using System.Drawing;
using System.Workflow.ComponentModel;
using System.Workflow.ComponentModel.Design;
using System.Workflow.ComponentModel.Compiler;
using System.Workflow.ComponentModel.Serialization;
using System.Workflow.Runtime;
using System.Workflow.Activities;
using System.Workflow.Activities.Rules;


using System.Data.Linq;
using System.Linq;

using Dropthings.DataAccess;

namespace Dropthings.Business.Activities
{
    public partial class CloneWidgetInstanceActivity : System.Workflow.ComponentModel.Activity
	{
        public CloneWidgetInstanceActivity()
		{
			InitializeComponent();
		}

        private static DependencyProperty WidgetZoneIdProperty = DependencyProperty.Register("WidgetZoneId", typeof(int), typeof(CloneWidgetInstanceActivity));

        [ValidationOptionAttribute(ValidationOption.Required)]
        [Browsable(true)]
        public int WidgetZoneId
        {
            get { return (int)base.GetValue(WidgetZoneIdProperty); }
            set { base.SetValue(WidgetZoneIdProperty, value); }
        }

        private static DependencyProperty WidgetInstanceProperty = DependencyProperty.Register("WidgetInstance", typeof(WidgetInstance), typeof(CloneWidgetInstanceActivity));

        [ValidationOptionAttribute(ValidationOption.Required)]
        [Browsable(true)]
        public WidgetInstance WidgetInstance
        {
            get { return (WidgetInstance)base.GetValue(WidgetInstanceProperty); }
            set { base.SetValue(WidgetInstanceProperty, value); }
        }


        protected override ActivityExecutionStatus Execute(ActivityExecutionContext executionContext)
        {

            this.WidgetInstance = DatabaseHelper.Insert<WidgetInstance>(DatabaseHelper.SubsystemEnum.WidgetInstance, (wi) =>
                {
                    wi.CreatedDate = this.WidgetInstance.CreatedDate;
                    wi.Expanded = this.WidgetInstance.Expanded;
                    wi.Height = this.WidgetInstance.Height;
                    wi.LastUpdate = this.WidgetInstance.LastUpdate;
                    wi.Maximized = this.WidgetInstance.Maximized;
                    wi.OrderNo = this.WidgetInstance.OrderNo;
                    wi.Resized = this.WidgetInstance.Resized;
                    wi.State = this.WidgetInstance.State;
                    wi.Title = this.WidgetInstance.Title;
                    wi.VersionNo = this.WidgetInstance.VersionNo;
                    wi.WidgetId = this.WidgetInstance.WidgetId;
                    wi.WidgetZoneId = this.WidgetZoneId;
                    wi.Width = this.WidgetInstance.Width;
               });

            return ActivityExecutionStatus.Closed;
        }
	}
}
